$(function() {
	showCondition(true, 0, 0, 1, []);
	var drg = $("#tabContent > .tab-pane.active").data();
	if (drg.value != "undefined") {
		paramTabPage[tabId] = drg;
	}

	var scoreQuota = [{
						"quotaCode" : "TotalScore",
						"quotaName" : "综合得分"
			},{
				"quotaCode" : "CapacityScore",
				"quotaName" : "产能得分"
			}, {
				"quotaCode" : "EfficiencyScore",
				"quotaName" : "效率得分"
			}, {
				"quotaCode" : "QualityScore",
				"quotaName" : "安全得分"
			}];
	paramTabPage[tabId].drg=perfQuotaDrg;
	paramTabPage[tabId].reg=perfQuotaReg;
	var role = $("#roleName_id").val();
	var deps = $("#deps_id").val();
	if (role == '科室' && deps != "") {
		paramTabPage[tabId].deps = deps;
	} else if (role == '科室' && deps == "") {
		paramTabPage[tabId].deps = "";
		drgUI.confirm({
					backdrop : 'static',
					content : '您还没授权科室，请联系管理员授权，点击确定系统将退出！',
					callSure : function() {
						$.post(contextPath + "/logout.dhc", function(
										data) {
									if (data.success) {
										window.location.href = data.data;
									}
								});
					}
				});
		return;
	}
	/*加载科室绩效综合评价*/
    getDepScore(scoreQuota, "dep", "loadDepNextLayerPerf");
	/*获取全部参与科室绩效指标比较汇总的科室*/
	medAffDepPerfDGCompareInit(perfQuotaDrg, perfQuotaReg);
	/* 全院各科室组DRGs指标综合比较汇总表*/
	loadTotalQuotaTable(totalQuota, "dep", "loadDepNextLayerPerf");
	if(role == '科室'){
		/*查看科室下医师*/
		$("#"+tabId+" #lookAllDoctor_id").css("display","block");
		$("#"+tabId+" #lookAllDoctor_id").click(function(){
			var param = jQuery.extend(true,{},paramTabPage[tabId]);
			param.upOnLevel = 'Hops';
			param.monitorType = 'Hops';
			param.isA = 0;
			openTab('/pages/yizheng/perf/ywcHospDoctorPerf.jsp', "全部|"+'医生比较','Hosp_Doctor_1', 'Hosp_Doctor_1',param);
		});
	}else{
		if(commonLayerConfig[0]=="0" && commonLayerConfig[1]=="1"){
			/*查看全院医师*/
			$("#"+tabId+" #lookAllDoctor_id").css("display","block");
			$("#"+tabId+" #lookAllDoctor_id").click(function(){
				var param = jQuery.extend(true,{},paramTabPage[tabId]);
				param.upOnLevel = 'Hops';
				param.monitorType = 'Hops';
				param.isA = 0;
				openTab('/pages/yizheng/perf/ywcHospDoctorPerf.jsp', "全部|"+'医生比较','Hosp_Doctor_1', 'Hosp_Doctor_1',param);
			});
		}
	}
});

/**
 *  @ Discription:获取科室信息并获取科室的比较雷达图
 * @Autor ：liuhongjun
 * @param sx
 * @param totalQuota
 * @param type
 * @returns any ywcDepPerf.js 2017年6月7日下午8:44:29
 */
function  medAffDepPerfDGCompareInit(perfQuotaDrg,perfQuotaReg){
    //绘制指标复选框
    loadQuotaCheckbox();
    var monitorType = 'dep';

    var map=drgUI.setAjaxData(tabId,map);
	// 获取科室数据
	$.post(contextPath+'/YiZhengHome/getDepInDG.dhc', map).done(function(result) {	
		 if(result.success ){
			 var depAll = result.data;
			 var avgFlag = true;//是否加载均值信息
			 if(jQuery.isEmptyObject(depAll)){//没有科室
   				 $('#'+tabId+' #depCodes ul').html("无数据");
			 }else{
				 //绘制复选框
				 var str="";
				 var descval = "全院均值";
				 var role = $("#roleName_id").val();
				 $('#'+tabId+' #depCodes ul').html("");
				 if(role=='科室'){//科室角色时 只管理一个科室 不显示比较对象
					 if(map.deps&&!(/,/.test(map.deps))) {
						 avgFlag = false;
						 $('#'+tabId+' .well').css("display","none");
					 }
					 descval="授权科室均值";
				 }else{
					 descval = "全院均值";
				 }
				 $.each(depAll, function (n, value) {
					 if(n==0){
		    			 str+="<label><input  checked='checked' type='checkbox' name='depcode' value='"+value.DEPCODE+"' descval='"+value.DEPDESC+"'/>"+value.DEPDESC+"&nbsp;&nbsp;</label>";
					 }else{
		    			 str+="<label><input type='checkbox' name='depcode' value='"+value.DEPCODE+"' descval='"+value.DEPDESC+"'/>"+value.DEPDESC+"&nbsp;&nbsp;</label>";
					 }
	    		 });
				 if(avgFlag){
					 str+="<label><input type='checkbox' id='hspstd' name='depcode' value='hspstd' descval='"+descval+"' />"+descval+"&nbsp;&nbsp;</label>";
				 }
				 $('#'+tabId+' #depCodes ul').append(str);
				 if(!avgFlag){//不显示均值的时候显示第一个科室的数据
					 $('#' + tabId + ' input[name="depcode"]').attr("checked",'checked');
				 }
				 if(depAll.length>5){
					 var strShowMore = "<div id='showMore'><a href='#' style='text-decoration:none'><i class='icon-plus-sign'style='font-size: 25px;'></i></a></div>";
					 // 添加已经选中的复选框
					 $('#' + tabId + ' #depCodes').append(strShowMore);
					 var $category = $('#' + tabId + ' #depCodes ul label:gt(6)');
					 $category.hide();
					 var $toggleBtn = $('#showMore a');
					 $toggleBtn.toggle(function() {
						 $category.show();
						 $(this).find('i').removeClass('icon-plus-sign').addClass('icon-minus-sign').css('color','red');
					 }, function() {
						 $category.hide();
						 $(this).find('i').removeClass('icon-minus-sign').addClass('icon-plus-sign').css('color','#428BCA');
					 });
				 }
				 //复选框绑定事件
				 $('#'+tabId+' input[name="depcode"]:checkbox').on('ifChanged', function(){
					 if($('#'+tabId+' input[name="depcode"]:checkbox:checked').size()==0){
						 $(this).attr('checked','checked');
					 }
                     drawRadarBySelectedQuota(monitorType);
	 			 });
			 }
             //初始化icheck
             $('#' + tabId + ' input').iCheck({
                 checkboxClass: 'icheckbox_square-blue',
                 radioClass: 'iradio_square-blue',
                 increaseArea: '10%' // optional
             });
             $('#' + tabId + ' #quotaPanel input').on('ifChanged', function () {
                 drawRadarBySelectedQuota(monitorType);
             });
             drawRadarBySelectedQuota(monitorType);
		 }
	 });
}
/**
 * 科室得分分析
 * @param {} totalQuota
 * @param {} monitorType
 * @param {} functionName
 */
function getDepScore(scoreQuota, monitorType, functionName) {
	var columns = [{
		"data" : "ddesco",
		"title" : "科室",
		"render":function(obj, type, full){
			if(commonLayerConfig[2]==1){
				return "<a title ='" + full.ccode
				+ "' href=\"javascript:"
				+ functionName + "('"
				+ full.ccode + "','"
				+ full.ddesc + "') \">"
				+ full.ddesc + "</a>";
			}else{
				return full.ddesc;
			}
		}
	 }, {
		"data" : "QuotaValue",
		"title" : "综合得分"
	}, {
		"data" : "CapacityScore",
		"title" : "产能得分"
	},  {
		"data" : "EfficiencyScore",
		"title" : "效率得分"
	},{
        "data" : "QualityScore",
        "title" : "安全得分"
    },{
		"data":"",
		"title":"操作",
		"render":function(obj, type, full){
		   var isA=0
			if(toNextLayerBoolPerf(monitorType)){
				isA=1;
			}else{
				isA=0;
			}
			return "<a class='jumplink' href=\"javascript:loadHospDoctor('" + full.ccode + "','" + full.ddesc + "','" + monitorType+ "','"+isA+"')\">医生比较</a>";
		}
	}];
	var datas = [];
	var ajaxCnt = scoreQuota.length;
	for (var i in scoreQuota) {
		var quotaCode = scoreQuota[i].quotaCode;
		getPerfScoreTable(quotaCode, monitorType,
				function(quotaCode, data) {
					var data_s = [];
					data_s = data_s.concat(data);
					if (datas.length <= 0) {
						datas = data_s;
					}
					mergeListcc(datas, data_s,'ccode','',quotaCode);
					ajaxCnt--;
				});
	}
	var timer = setInterval(function() {
			if (ajaxCnt == 0) {
				clearInterval(timer);
				for(var i in datas){
					datas[i].QuotaValue=datas[i].TotalScore;
				}
				var paramsDataTables={order:[[1,'desc']],ordering:true};
				$("#" + tabId + " #depScore_table").drgsDataTable(columns, datas, paramsDataTables);

			}
		}, 200);
};
/**
 * 跳转病区
 * @param {} code
 * @param {} desc
 */
function loadDepNextLayerPerf(code,desc){
	var param = jQuery.extend(true,{},paramTabPage[tabId]);
	param.depCode = code;
	openTab('/pages/yizheng/perf/ywcWardPerf.jsp', desc+'病区绩效',code+'dep_ward_Perf', code+'dep_ward_Perf',param);
}






